package com.changyinBus.system.service.impl;

import com.changyinBus.common.core.domain.entity.SysProd;
import com.changyinBus.system.mapper.SysProdCateMapper;
import com.changyinBus.system.mapper.SysProdMapper;
import com.changyinBus.system.service.ISysProdService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysProdServiceImpl implements ISysProdService {
    @Resource
    private SysProdMapper sysProdMapper;
    @Resource
    private SysProdCateMapper sysProdCateMapper;

    @Override
    public List<SysProd> selectProdList(SysProd prod) {
        return sysProdMapper.selectProdList(prod);
    }

    @Override
    public SysProd selectProdById(Long prodId) {
        return sysProdMapper.selectProdById(prodId);
    }

    @Override
    public int insertProd(SysProd prod) {
        //补充分类参数
        /*SysProdCate cate = sysProdCateMapper.selectProdCateById(prod.getCateId());
        if(cate == null) {
            throw new ServiceException(String.format("所属分类为必填!"));
        }
        prod.setCateName(cate.getProdCateName());
        prod.setAncestors(cate.getAncestors());*/
        return sysProdMapper.insertProd(prod);
    }

    @Override
    public int updateProd(SysProd prod) {
        //补充分类参数
        /*SysProdCate cate = sysProdCateMapper.selectProdCateById(prod.getCateId());
        if(cate == null) {
            throw new ServiceException(String.format("所属分类为必填!"));
        }
        prod.setCateName(cate.getProdCateName());
        prod.setAncestors(cate.getAncestors());*/
        return sysProdMapper.updateProd(prod);
    }

    @Override
    public int updateProdStatus(SysProd prod) {
        return sysProdMapper.updateProdStatus(prod.getProdId(), prod.getStatus());
    }

    @Override
    public int deleteProdById(Long prodId) {
        return sysProdMapper.deleteProdById(prodId);
    }
}
